<?php


namespace app\api\controller;
use app\api\lists\TaskLists;
use app\api\logic\TaskLogic;
use app\api\validate\TaskValidate;

class TaskController extends BaseShopController
{
    /**
     * @notes 添加新数据
     * @return \think\response\Json
     * @author ljj
     * @date 2022/2/24 10:52 上午
     */
    public function getdata(){
        $params = (new TaskValidate())->get()->goCheck('add');
        $data = json_decode($params['params'], true);
        $uploadsIndex  =strrpos($data['uri'], "uploads");
        $data['uri'] = substr($data['uri'], $uploadsIndex);

        $data['user_id'] = $this->userId;
        $result = (new TaskLogic())->getdata($data);
        if (false === $result) {
            return $this->fail(TaskLogic::getError());
        }
        return $this->success('添加成功',[],1,1);
    }

    /**
     * @notes 违规列表
     * @return \think\response\Json
     * @author ljj
     * @date 2022/2/18 10:55 上午
     */
    public function lists()
    {
        return $this->dataLists(new TaskLists());
    }

    /**
     * @notes 违规列表
     * @return \think\response\Json
     * @author ljj
     * @date 2022/2/18 10:55 上午
     */
    public function getmapplan()
    {
        $getArr = $this->request->get();
        if (!isset($getArr['location']) || $getArr['location'] == '') {
            return $this->fail('经纬度缺失');
        }
        if ($getArr['id'] == ''){
            return $this->fail('订单id缺失');
        }
        $get = $getArr['location'];
        $id=$getArr['id'];
        $to = (new TaskLogic())->findlat($id);

        $result = TaskLogic::getaddress($get, $to);
        if ($result['status'] !== 0) {
            return $this->fail($result['message']);
        }
        return $this->success('',$result);
    }
}